import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;


/**
 * @author tandaica0612
 */
public class DecectKeyPress extends MIDlet {
    private Display display;
    private KeyPressInput keypressinput;

    public DecectKeyPress() {
        keypressinput = new KeyPressInput(true);
        display = Display.getDisplay(this);
    }
    
    public void startApp() {
        display.setCurrent(keypressinput);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
}
//
//
class KeyPressInput extends GameCanvas {
    protected KeyPressInput(boolean suppressKeyEvents) {
		super(suppressKeyEvents);
		// TODO Auto-generated constructor stub
	}

	protected void keyPressed() {
        int gameaction = getKeyStates();
        if((gameaction & UP_PRESSED) != 0){
            System.out.print("Bam phim Up");
        }
        if((gameaction & DOWN_PRESSED) != 0){
            System.out.print("Bam phim Down");
        }
        if((gameaction & LEFT_PRESSED) != 0){
            System.out.print("Bam phim Left");
        }
        if((gameaction & RIGHT_PRESSED) != 0){
            System.out.print("Bam phim Right");
        }
    }
   
}